﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace AIFSContentManagementSystem.Criteria
{
    using Messages;

    public class CriteriaService : ICriteriaService
    {
        IRepositoryMap repositoryMap;

        public CriteriaService(IRepositoryMap RepositoryMap)
        {
            repositoryMap = RepositoryMap;
        }

        public GetCriterionResponse Process(Messages.GetCriterionRequest request)
        {
            GetCriterionResponse response = new GetCriterionResponse();
            
            if (!request.CriteriaId.HasValue)
                response.AddErrorMessage("Criteria id is required");

            //Get the criterion
            ICriteriaRepository repository = repositoryMap.Get<ICriteriaRepository>();
            Criterion criterion = repository.GetCriterion(request.CriteriaId);
            
            if (criterion != null)
            {
                response.AddCriterion(criterion);
            }

            return response;
        }
    }
}